#include <iostream>
using namespace std;
#include <stdlib.h>
#include <string.h>
#include "LinkStack.cpp"
//copy
//重载=
//把类变成了 可复制 深拷贝
struct Teacher
{
public:
        char name[64];
        int age;
        char *pdes;
        Teacher(){
                memset(name,0,sizeof(name));
                age = 0;
                pdes = NULL;
        }
        ~Teacher(){
                if(pdes != NULL){
                     delete pdes;  
                     pdes = NULL; 
                }
        }
        Teacher(Teacher &t){
                pdes = new char[100];
                strcpy(this->pdes, t.pdes);
                strcpy(this->name,t.name);
                age = t.age;
        }
        Teacher& operator=(Teacher &t){
                //把之前的内存空间释放掉
                if(pdes){
                        delete pdes;
                        pdes = NULL;
                }
                pdes = new char[100];
                if(t.pdes){
                        strcpy(this->pdes, t.pdes);
                }
                strcpy(this->name,t.name);
                age = t.age;
                return *this;
        }
};
void main_linkstack_play()
{
        //创建栈
        LinkStack<Teacher> stack;
        
        Teacher t1,t2,t3,tmp;
        t1.age = 31;
        t2.age = 32;
        t3.age = 33;

        stack.push(t1);
        stack.push(t2);
        stack.push(t3);

        //获取栈顶元素
        stack.top(tmp);
        cout<<"栈顶: "<<tmp.age <<endl;
        cout<<"栈size: "<<stack.size() <<endl;

        //栈的删除
        while (stack.size() > 0){
                stack.pop(tmp);
                cout<<tmp.age<<" ";
        }
}
int main(int argc, char const *argv[])
{
        main_linkstack_play();
        return 0;
}
